package com.api.gbhg.luoao.web;

import com.alibaba.fastjson.JSON;
import com.api.gbhg.liuwenbo.utils.FormatUtil;
import com.api.gbhg.luoao.utils.PageEntity;
import com.api.gbhg.luoao.utils.VersionQuery;
import com.api.gbhg.zengping.dao.PropertyManagementCostDao;
import weaver.conn.RecordSet;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * 公共图书馆、阅览室订阅审批列表
 *
 */
public class PublicBookApprovalAction {

    @POST
    @Path("/PublicBookApprovalAction")
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.APPLICATION_JSON)
    public String pbal(Map<String,String> param){
        PropertyManagementCostDao rmcd=new PropertyManagementCostDao();
        String requsetid = param.get("requestId");
        //查询版本主表

        RecordSet version = VersionQuery.getbooks("09",requsetid);
        Map<String,Object>[] map = new HashMap[version.getArray().size()];
        int i = 0;
        while (version.next()){
            map[i] = new HashMap<>();
            String xmmin = version.getString("xmmin");
            String departmentmark = version.getString("departmentmark");
            int jbr = version.getInt("jbr");//经办人id
            int id = version.getInt("id");//id
            map[i].put("lcjlsqjlid",version.getInt("lcjlsqjlid"));//流程id
            map[i].put("xmmin",xmmin);//合同名称
            map[i].put("sbdw",version.getString("subcompanyname"));//申报单位
            map[i].put("sbks",version.getString("departmentmark"));//申报科室
            map[i].put("yszje", FormatUtil.DmFormat(version.getDouble("yszje")));//总金额
            RecordSet userNameById = rmcd.getUserNameById(jbr);
            userNameById.next();
            String loginid = userNameById.getString("loginid");
            if(loginid==""){
                loginid="系统管理员";
            }
            map[i].put("jbr",loginid);//经办人
            map[i].put("zfcgyswy",FormatUtil.DmFormat(version.getDouble("zfcgyswy")));//政府采购预算
            map[i].put("hwgz",FormatUtil.DmFormat(version.getDouble("hwgz")));//货物购置预算
            map[i].put("gc",FormatUtil.DmFormat(version.getDouble("gc")));//修缮工程预算
            map[i].put("fw",FormatUtil.DmFormat(version.getDouble("fw")));//服务预算
            map[i].put("xecg",FormatUtil.DmFormat(version.getDouble("xecg")));//小额采购预算
            RecordSet getdetail = VersionQuery.getdetail("uf_ggtsgylsdyspbbb_dt1", id);
            int ndys = 0;//拟订阅数
            int sndyzs = 0;//上年订阅数
            while (getdetail.next()){
                ndys = getdetail.getInt("ndys")+ndys;
                sndyzs = getdetail.getInt("sndyzs")+sndyzs;
            }
            map[i].put("ndys",ndys);
            map[i].put("sndyzs",sndyzs);
            i++;
        }
        PageEntity page = new PageEntity();
        page.setList(map);
        page.setFromtable("uf_ggtsgylsdyspbbb");
        return JSON.toJSONString(page);
    }
    public String pbal1(String requsetid){
        PropertyManagementCostDao rmcd=new PropertyManagementCostDao();
//        String requsetid = param.get("requestId");
        //查询版本主表

        RecordSet version = VersionQuery.getbooks("09",requsetid);
        Map<String,Object>[] map = new HashMap[version.getArray().size()];
        int i = 0;
        while (version.next()){
            map[i] = new HashMap<>();
            String xmmin = version.getString("xmmin");
            String departmentmark = version.getString("departmentmark");
            int jbr = version.getInt("jbr");//经办人id
            int id = version.getInt("id");//id
            map[i].put("lcjlsqjlid",version.getInt("lcjlsqjlid"));//流程id
            map[i].put("xmmin",xmmin);//合同名称
            map[i].put("sbdw",version.getString("subcompanyname"));//申报单位
            map[i].put("sbks",version.getString("departmentmark"));//申报科室

            BigDecimal yszje = new BigDecimal(version.getString("yszje"));
            map[i].put("yszje", yszje.divide(new BigDecimal("10000"),4, BigDecimal.ROUND_HALF_UP));//总金额
            RecordSet userNameById = rmcd.getUserNameById(jbr);
            userNameById.next();
            String lastname = userNameById.getString("lastname");
            if(lastname==""){
                lastname="系统管理员";
            }
            map[i].put("jbr",lastname);//经办人
            BigDecimal zfcgyswy = new BigDecimal(version.getString("zfcgyswy"));
            map[i].put("zfcgyswy",zfcgyswy.divide(new BigDecimal("10000"),4, BigDecimal.ROUND_HALF_UP));//政府采购预算

            BigDecimal hwgz = new BigDecimal(version.getString("hwgz"));
            map[i].put("hwgz",hwgz.divide(new BigDecimal("10000"),4, BigDecimal.ROUND_HALF_UP));//货物购置预算

            BigDecimal gc = new BigDecimal(version.getString("gc"));
            map[i].put("gc",gc.divide(new BigDecimal("10000"),4, BigDecimal.ROUND_HALF_UP));//修缮工程预算

            BigDecimal fw = new BigDecimal(version.getString("fw"));
            map[i].put("fw",fw.divide(new BigDecimal("10000"),4, BigDecimal.ROUND_HALF_UP));//服务预算

            BigDecimal xecg = new BigDecimal(version.getString("xecg"));
            map[i].put("xecg",xecg.divide(new BigDecimal("10000"),4, BigDecimal.ROUND_HALF_UP));//小额采购预算
            RecordSet getdetail = VersionQuery.getdetail("uf_ggtsgylsdyspbbb_dt1", id);
            int ndys = 0;//拟订阅数
            int sndyzs = 0;//上年订阅数
            while (getdetail.next()){
                ndys = getdetail.getInt("ndys")+ndys;
                sndyzs = getdetail.getInt("sndyzs")+sndyzs;
            }
            map[i].put("ndys",ndys);
            map[i].put("sndyzs",sndyzs);
            i++;
        }
        PageEntity page = new PageEntity();
        page.setList(map);
        page.setFromtable("uf_ggtsgylsdyspbbb");
        return JSON.toJSONString(page);
    }

}
